const express = require('express');
const app = express();
const morgan = require('morgan');
const cors = require('cors');
const router = require('./router/index');
const errorHandler = require('./middleware/error-handler');
require('./model/index');


app.use(cors());
app.use(morgan('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

const port = process.env.port || 3000;

//挂载路由
app.use('/api',router);


//错误处理，挂载统一处理服务端的中间件
app.use(errorHandler());

app.listen(port, () => {
    console.log(`Server is running on port ${port}`);
});
